<?php

namespace Yunqing\CsCode;

use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;

class Plugin implements PluginInterface
{
    public function activate(Composer $composer, IOInterface $io)
    {
        copy(__DIR__ . '/../commitlint.sh', __DIR__ . '/../../../../commitlint.sh');
        copy(__DIR__ . '/../recommit.sh', __DIR__ . '/../../../../recommit.sh');
        chmod(__DIR__ . '/../../../../commitlint.sh', 0755);
        chmod(__DIR__ . '/../../../../recommit.sh', 0755);
    }

    public function deactivate(Composer $composer, IOInterface $io)
    {
        copy(__DIR__ . '/../commitlint.sh', __DIR__ . '/../../../../commitlint.sh');
        copy(__DIR__ . '/../recommit.sh', __DIR__ . '/../../../../recommit.sh');
        chmod(__DIR__ . '/../../../../commitlint.sh', 0755);
        chmod(__DIR__ . '/../../../../recommit.sh', 0755);
    }

    public function uninstall(Composer $composer, IOInterface $io)
    {
        if (file_exists(__DIR__ . '/../../../../commitlint.sh')) {
            unlink(__DIR__ . '/../../../../commitlint.sh');
        }
        if (file_exists(__DIR__ . '/../../../../recommit.sh')) {
            unlink(__DIR__ . '/../../../../recommit.sh');
        }
    }
}
